package com.tzbank.wisdom.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.tzbank.entity.Charge;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;
import com.tzbank.wisdom.dao.ChargeMapper;
import com.tzbank.wisdom.service.ChargeService;

import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
@Service
@Slf4j
public class ChargeServiceImpl implements ChargeService {
	@Resource
	private ChargeMapper chargeMapper;
	
	@Override
	public Map<String, Object> getCharge(Charge charge) {
		
		Map<String, Object> map=chargeMapper.getCharge(charge);
		if(map!=null) {
			for(Map.Entry<String, Object> entry:map.entrySet()) {
				if("commentCode".equals(entry.getKey())) {
					String[] s=entry.getValue().toString().split(";"); 
					entry.setValue(s);
				}
			}	
		}

		return  map;
	}

	@Override
	public Map<String, Object> updateCharge(Charge charge) {
		log.info("请求参数：[{}]",JSONObject.fromObject(charge).toString());
		
		Map<String, Object> chargeQry=null;
		if(charge.getOriTranDate()!=null&&charge.getTellSeqNo()!=null) {
			chargeQry= chargeMapper.getCharge(charge);
		}
		int result ;
		if(chargeQry!=null) {
			result = chargeMapper.updateCharge(charge);
			log.info("更新[{}]",result);

		}else {
			result = chargeMapper.saveCharge(charge);
			log.info("新增[{}]",result);

		}

		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	
	}

	@Override
	public Map<String, Object>  getLable() {
		Map result=new HashMap();
		List list=chargeMapper.getLable();
		result.put("resulList", list);
		
		return result;
	}

}
